﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace SH.STD.Web.Committe
{
    public partial class CommittePaperList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Master.SetTab(Model.TabType.Committe);

            if (!Page.IsPostBack)
            {
                this.BindData(this.GetSql());
            }
        }

        private void BindData(string sql)
        {
            var dt = Cmn.DB.getDataTable(sql);

            this.rptPapers.DataSource = dt;
            this.rptPapers.DataBind();
            this.lblCnt1.Text = dt.Rows.Count.ToString();
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            this.BindData(this.GetSql());
        }
        protected void btnClear_Click(object sender, EventArgs e)
        {
            this.txtProjectName.Text = String.Empty;

            this.BindData(this.GetSql());
        }

        private string GetSql()
        {
            var ret = @"
select a.ID,a.Name
from Committee_Paper a
where a.Status=1 and ";
            var where = String.Empty;
            if (!String.IsNullOrEmpty(this.txtProjectName.Text.Trim()))
            {
                where += "a.Name like '%" + this.txtProjectName.Text.Trim() + "%' and ";
            }
            ret = where == String.Empty ? ret.Substring(0, ret.LastIndexOf("and ")) : ret + " " + where.Substring(0, where.LastIndexOf("and "));

            return ret;
        }
    }
}